package com.link.base.base.approval.controller;

import com.link.base.base.approval.model.FlowUser;
import com.link.base.base.approval.service.FlowUserService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.model.BasicModel;
import com.link.core.basic.query.QueryParams;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.BasicServiceException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 当前审批人查询
 *
 * @author 姚江漪
 * @date 2019/06/10 15:00
 */

@Controller
@RequestMapping("/link/flowUser")
public class FlowUserController extends BasicController<FlowUser> {
    private static final Logger logger = LogManager.getLogger(FlowUserController.class);

    @Resource
    private FlowUserService flowUserService;

    @Override
    public BasicService<FlowUser> getBasicService() {
        return flowUserService;
    }

    /**
     * 查询当前flow对应的当前审批人列表
     *
     * @author 姚江漪
     * @date 2019/06/10 15:00
     */
    @RequestMapping({"/queryByFLowId"})
    @ResponseBody
    @Override
    public Map<String, Object> queryByExamplePage(@JsonParam QueryParams qps, @JsonParam FlowUser entity,
                                                  HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        HashMap result = new HashMap();
        try {
            qps.preDealSecurity(request);
            FlowUser flowUser = BasicModel.transformClass(entity, qps);
            this.beforQueryAllOrExample(flowUser, request);
            this.beforQueryExample(flowUser, request);
            List<FlowUser> list = flowUserService.queryByFLowId(flowUser);
            result.put("success", true);
            result.put("rows", list);
            result.put("total", getCount(flowUser, list.size()));
        } catch (BasicServiceException var9) {
            logger.error("查询当前审批人异常: ", var9);
            result.put("success", false);
            result.put("rows", new ArrayList());
            result.put("result", var9.getMessage());
            result.put("detailMessage", var9.getDetailMessage());
        } catch (Exception var10) {
            logger.error("查询当前审批人异常: ", var10);
            result.put("success", false);
            result.put("rows", new ArrayList());
            result.put("result", var10.getMessage());
        }
        return result;
    }
}
